package reback;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class item46 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> track = new LinkedList<>();
        reback(nums,res,track);
    return res;
    }

    private void reback(int[] nums, List<List<Integer>> res, List<Integer> track) {
        if(track.size()== nums.length)
        {
            res.add(new ArrayList<>(track));
        }
        for (int i = 0; i <nums.length ; i++) {
            if(track.contains(nums[i]))
                continue;
            track.add(nums[i]);
            reback(nums,res,track);
            track.remove(track.size()-1);
        }
    }
}
